/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package intershopxssscanner.filters;

import java.util.ArrayList;
import java.util.Properties;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Willem
 */
public class ReplaceStringFilter extends FilterAdapter {

    private String regex;
    private String replace = "";
    private int id;

    public String doFilterLine(String input) {
        //Pattern.compile(regex).matcher(str).replaceAll(repl)
        return input.replaceAll(getRegex().trim(), replace);
    }
    
    @Override
    public ArrayList<String> doFilter(ArrayList<String> input) {
        ArrayList<String> output = new ArrayList<String>();

        for (String line : input) {
            line = doFilterLine(line);

            if (line == null) {
                break;
            }
            else{
                output.add(line);
            }
        }

        return output;
    }

    @Override
    public void loadSettings(Properties prop, String id) {
        setRegex(prop.getProperty(Filter.PREFIX + id + Filter.DEL + Filter.REGEX));

        String setting = prop.getProperty(Filter.PREFIX + id + Filter.DEL + Filter.SETTINGS);
        replace = (String.valueOf(setting.split(Filter.SETTINGS_DEL)[0]));
    }

    /**
     * @return the regex
     */
    public String getRegex() {
        return regex;
    }

    /**
     * @param regex the regex to set
     */
    public void setRegex(String regex) {
        this.regex = regex;
    }

    
}
